#include "DispatcherThread.h"
#include "WatermarkManager.h"
#include <log/log.h>

namespace android {

DispatcherThread::DispatcherThread(WatermarkManager* manager, BufferQueue<WMarkBuffer>* queue)
{
    mManager = manager;
    mBufferQueue = queue;
}

DispatcherThread::~DispatcherThread() {

}

void DispatcherThread::start() {
    this -> run("DispatcherThread", PRIORITY_HIGHEST);
}

void DispatcherThread::onDataReady() {
    mBarrier.open();
}

void DispatcherThread::stop() {
    requestExitAndWait();
}

bool DispatcherThread::threadLoop() {
    mBarrier.wait();
    mBarrier.close();

    WMarkBuffer* buf = mBufferQueue -> dequeueConsumerBuffer();

    //handle
    printf("handle. 摄像头已经收到 即将要转换的字符串内容是\n");
    mManager->onDispatcherResult(buf);

    mBufferQueue -> enqueueProducerBuffer(buf);
    return true;
}


} //namespace
